/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bussiness;

import DatabaseAccess.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author user
 */
public class NhanVien {
    private String MaNV;
    private String TenNV;
    private String ChucVu;
    private String GioiTinh;
    DBHelper conn = new DBHelper();

    /**
     * @return the MaNV
     */
    public String getMaNV() {
        return MaNV;
    }

    /**
     * @param MaNV the MaNV to set
     */
    public void setMaNV(String MaNV) {
        this.MaNV = MaNV;
    }

    /**
     * @return the TenNV
     */
    public String getTenNV() {
        return TenNV;
    }

    /**
     * @param TenNV the TenNV to set
     */
    public void setTenNV(String TenNV) {
        this.TenNV = TenNV;
    }

    /**
     * @return the ChucVu
     */
    public String getChucVu() {
        return ChucVu;
    }

    /**
     * @param ChucVu the ChucVu to set
     */
    public void setChucVu(String ChucVu) {
        this.ChucVu = ChucVu;
    }

    /**
     * @return the GioiTinh
     */
    public String getGioiTinh() {
        return GioiTinh;
    }

    /**
     * @param GioiTinh the GioiTinh to set
     */
    public void setGioiTinh(String GioiTinh) {
        this.GioiTinh = GioiTinh;
    }
    public NhanVien(){}
    public NhanVien(String MaNV, String TenNV, String ChucVu, String GioiTinh){
        this.setMaNV(MaNV);
        this.setTenNV(TenNV);
        this.setChucVu(ChucVu);
        this.setGioiTinh(GioiTinh);
    }
    public int insertNhanVien(NhanVien a) throws SQLException
    {
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMaNV());
            v.add(a.getTenNV());
            v.add(a.getChucVu());
            v.add(a.getGioiTinh());
            i=conn.executeUpdate("sp_InsertNhanVien",v);
        }catch(SQLException ex){}
        return i;
    }
    public int updateNhanVien(NhanVien a) throws SQLException
    {
        DBHelper obj =new DBHelper();
        int i = 0;
        try{
            Vector v = new Vector();
            v.add(a.getMaNV());
            v.add(a.getTenNV());
            v.add(a.getChucVu());
            v.add(a.getGioiTinh());
            i=obj.executeUpdate("sp_UpdateNhanVien",v);
        }catch(SQLException ex){}
        return i;
    }
    public int DelNhanVien(String MaNV) throws SQLException
    {
        int i=0;
        try
        {
            Vector paramList=new Vector();
            paramList.add(MaNV);            
            i=conn.executeUpdate("sp_DelNhanVien",paramList);
        }
        catch(SQLException sqlex)
        {
            
        }
        return i;
    }
    public Vector getAllNhanVien() throws SQLException
    {
        Vector v = new Vector();
        try 
        {
            ResultSet rs = conn.executeQuery("sp_getAllNhanVien");
            while(rs.next())
            {                  
                NhanVien b = new NhanVien();
                b.setMaNV(rs.getString(1));
                b.setTenNV(rs.getString(2));
                b.setChucVu(rs.getString(3));
                b.setGioiTinh(rs.getString(4));
                v.add(b);                         
            }
        } 
        catch(SQLException sqle) 
        {            
        }
        return v;
    }
    public Vector getNhanVien_MaNV(String MaNV) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(MaNV);
        try{
            ResultSet rs = conn.executeQuery("sp_getMaNV", v1);
            while(rs.next()){
                NhanVien b = new NhanVien();
                b.setMaNV(rs.getString(1));
                b.setTenNV(rs.getString(2));
                b.setChucVu(rs.getString(3));
                b.setGioiTinh(rs.getString(4));
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v; 
    }
    public Vector getNCC_TenNV(String TenNV) throws SQLException
    {
        Vector v = new Vector();
        Vector v1 = new Vector();
        v1.add(TenNV);
        try{
            ResultSet rs = conn.executeQuery("sp_getTenNV", v1);
            while(rs.next()){
                NhanVien b = new NhanVien();
                b.setMaNV(rs.getString(1));
                b.setTenNV(rs.getString(2));
                b.setChucVu(rs.getString(3));
                b.setGioiTinh(rs.getString(4));
                v.add(b);
            }
        }catch(SQLException sqle) {}
        return v;
    }
    
}
